//
//  HMHomeViewController.m
//  HMMeituan19HD
//
//  Created by 邢广 on 16/9/14.
//  Copyright © 2016年 xg. All rights reserved.
//

#import "HMHomeViewController.h"
#import "HMHomeNavView.h"
#import "HMCetegoryViewController.h"

@interface HMHomeViewController ()

@end

@implementation HMHomeViewController

static NSString * const reuseIdentifier = @"Cell";

- (instancetype)init
{
    self = [super initWithCollectionViewLayout:[UICollectionViewFlowLayout new]];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.collectionView.backgroundColor = HMColor(230, 230, 230);
    
    // Register cell classes
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
    
    // 设置左边导航按钮
    [self setLiftNav];
    // 设置右边导航按钮
    [self setRightNav];

}


- (void)setLiftNav {
    // logo
    UIBarButtonItem *logoItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"icon_meituan_logo"] style:UIBarButtonItemStylePlain target:nil action:nil];

    logoItem.enabled = NO;
    
    // 分类
    HMHomeNavView *cetegoryNavView = [HMHomeNavView homeNavView];
    UIBarButtonItem *cetegoryItem = [[UIBarButtonItem alloc]initWithCustomView:cetegoryNavView];
    // 点击事件
    [cetegoryNavView addTarget:self action:@selector(cetegoryClick) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    // 区域
    HMHomeNavView *districtNavView = [HMHomeNavView homeNavView];
    UIBarButtonItem *districtItem = [[UIBarButtonItem alloc]initWithCustomView:districtNavView];

    // 排序
    HMHomeNavView *sortNavView = [HMHomeNavView homeNavView];
    UIBarButtonItem *sortItem = [[UIBarButtonItem alloc]initWithCustomView:sortNavView];

    self.navigationItem.leftBarButtonItems = @[logoItem, cetegoryItem, districtItem, sortItem];
}


- (void)setRightNav {
    
    UIBarButtonItem *mapItem = [UIBarButtonItem barBuutonItemWithTarget:self action:@selector(mapItemClick) icon:@"icon_map" highlighticon:@"icon_map_highlighted"];
    mapItem.customView.width = 60;
    
    UIBarButtonItem *searchItem = [UIBarButtonItem barBuutonItemWithTarget:self action:@selector(searchItemClick) icon:@"icon_search" highlighticon:@"icon_search_highlighted"];
    mapItem.customView.width = 60;
    
    self.navigationItem.rightBarButtonItems = @[mapItem, searchItem];
}



- (void)cetegoryClick {
    
    // Popover
    HMCetegoryViewController *cetegoryVC = [[HMCetegoryViewController alloc]init];
    cetegoryVC.modalPresentationStyle = UIModalPresentationPopover;
    UIPopoverPresentationController *popVC = cetegoryVC.popoverPresentationController;
    popVC.barButtonItem = self.navigationItem.leftBarButtonItems[1];
    [self presentViewController:cetegoryVC animated:YES completion:nil];
}

- (void)mapItemClick {
    NSLog(@"点击地图");

}

- (void)searchItemClick {
    NSLog(@"点击搜索");
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
#warning Incomplete implementation, return the number of sections
    return 0;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of items
    return 0;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    
    // Configure the cell
    
    return cell;
}

#pragma mark <UICollectionViewDelegate>

/*
// Uncomment this method to specify if the specified item should be highlighted during tracking
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
	return YES;
}
*/

/*
// Uncomment this method to specify if the specified item should be selected
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
*/

/*
// Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
	return NO;
}

- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	return NO;
}

- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	
}
*/

@end
